package com.java2007.hotel.service.impl;

import com.java2007.hotel.dao.UserDao;
import com.java2007.hotel.dao.impl.UserDaoImpl;
import com.java2007.hotel.pojo.Order;
import com.java2007.hotel.pojo.User;
import com.java2007.hotel.service.PayService;
import com.java2007.hotel.utils.JdbcUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Reckeys
 * @version V1.0
 * @date 2021/01/28
 **/
public class PayServiceImpl implements PayService {
    private UserDao userDao = new UserDaoImpl();

    /**
     * 支付操作
     * @param order
     * @param user
     * @return
     */
    @Override
    public User pay(Order order, User user) {
        user.setUserMoney(user.getUserMoney() - order.getOrderPrice());
        user.setUserUpdateTime(new Date());
        try {
            JdbcUtils.startTransactions();
            userDao.updateUser(user);
            JdbcUtils.commit();
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            JdbcUtils.rollBack();
            return null;
        }
    }
}
